package com.clinic.service.impl;

import com.clinic.dao.ClinicpatientDao;
import com.clinic.entity.Clinicpatient;
import com.clinic.service.ClinicpatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Clinicpatient)表服务实现类
 *
 * @author makejava
 * @since 2020-11-12 15:55:16
 */
@Service
public class ClinicpatientServiceImpl implements ClinicpatientService {
    @Autowired(required = false)
    private ClinicpatientDao clinicpatientDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pid 主键
     * @return 实例对象
     */
    @Override
    public Clinicpatient queryById(Integer pid) {
        return this.clinicpatientDao.queryById(pid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Clinicpatient> queryAllByLimit(int offset, int limit) {
        return this.clinicpatientDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param clinicpatient 实例对象
     * @return 实例对象
     */
    @Override
    public Clinicpatient insert(Clinicpatient clinicpatient) {
        this.clinicpatientDao.insert(clinicpatient);
        return clinicpatient;
    }

    /**
     * 修改数据
     *
     * @param clinicpatient 实例对象
     * @return 实例对象
     */
    @Override
    public Clinicpatient update(Clinicpatient clinicpatient) {
        this.clinicpatientDao.update(clinicpatient);
        return this.queryById(clinicpatient.getPid());
    }

    /**
     * 通过主键删除数据
     *
     * @param pid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pid) {
        return this.clinicpatientDao.deleteById(pid) > 0;
    }


    //查询所有患者
    @Override
    public List<Clinicpatient> findAllPatients() {
        List<Clinicpatient> clinicpatients=clinicpatientDao.findAllPatients();
        return clinicpatients;
    }
    //修改患者信息
    @Override
    public int updatePatients(int pid) {
        int updatePatients = clinicpatientDao.updatePatients(pid);
        return updatePatients;
    }
    //删除某一条患者数据
    @Override
    public boolean deletePatient(int pid) {
        int deletePatient = clinicpatientDao.deletePatient(pid);
        if (deletePatient>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean addPatient(Clinicpatient clinicpatient) {
        int patient= clinicpatientDao.addPatient(clinicpatient);
        if (patient>0){
            return true;
        }
        return false;
    }
}